using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.SimpleTemp.Repositories.Sys;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class PX_ExamUserQuestionsService : BaseAppService<PX_ExamUserQuestionsDto, PX_ExamUserQuestions , PX_ExamUserQuestionsRepository>
        {
        readonly ExcelHelp _excelHelp;
        public PX_ExamUserQuestionsService (PX_ExamUserQuestionsRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<PX_ExamUserQuestions, PX_ExamUserQuestionsDto>
            GetLoadPageOffsetMode(PagingModel<PX_ExamUserQuestionsDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("PersonID","=") //
         .Add("Times","=") //
         .Add("QuesiontID","=") //
         .Add("QuestionContent","=") //
         .Add("CorrectOption","=") //
         .Add("FirstOption","=") //
         .Add("LastOption","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  PX_ExamUserQuestions() {
                Id = model.Id,
PersonID= model.PersonID,//
Times= model.Times,//
QuesiontID= model.QuesiontID,//
QuestionContent= model.QuestionContent,//
CorrectOption= model.CorrectOption,//
FirstOption= model.FirstOption,//
LastOption= model.LastOption,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<PX_ExamUserQuestionsDto>> GetList(PagingModel<PX_ExamUserQuestionsDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<PX_ExamUserQuestionsDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.PersonID,
PersonID_title ="",
model.Times,
Times_title ="",
model.QuesiontID,
QuesiontID_title ="",
model.QuestionContent,
QuestionContent_title ="",
model.CorrectOption,
CorrectOption_title ="",
model.FirstOption,
FirstOption_title ="",
model.LastOption,
LastOption_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
